1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gdk.PaintableT; 26 27 public import gdk.PaintableIF; 28 public import gdk.Snapshot; 29 public import gdk.c.functions; 30 public import gdk.c.types; 31 public import glib.ConstructionException; 32 public import gobject.ObjectG; 33 public import gobject.Signals; 34 public import std.algorithm; 35 36 37 /** 38 * `GdkPaintable` is a simple interface used by GTK to represent content that 39 * can be painted. 40 * 41 * The content of a `GdkPaintable` can be painted anywhere at any size 42 * without requiring any sort of layout. The interface is inspired by 43 * similar concepts elsewhere, such as 44 * [ClutterContent](https://developer.gnome.org/clutter/stable/ClutterContent.html), 45 * [HTML/CSS Paint Sources](https://www.w3.org/TR/css-images-4/#paint-source), 46 * or [SVG Paint Servers](https://www.w3.org/TR/SVG2/pservers.html). 47 * 48 * A `GdkPaintable` can be snapshot at any time and size using 49 * [method@Gdk.Paintable.snapshot]. How the paintable interprets that size and 50 * if it scales or centers itself into the given rectangle is implementation 51 * defined, though if you are implementing a `GdkPaintable` and don't know what 52 * to do, it is suggested that you scale your paintable ignoring any potential 53 * aspect ratio. 54 * 55 * The contents that a `GdkPaintable` produces may depend on the [class@GdkSnapshot] 56 * passed to it. For example, paintables may decide to use more detailed images 57 * on higher resolution screens or when OpenGL is available. A `GdkPaintable` 58 * will however always produce the same output for the same snapshot. 59 * 60 * A `GdkPaintable` may change its contents, meaning that it will now produce 61 * a different output with the same snapshot. Once that happens, it will call 62 * [method@Gdk.Paintable.invalidate_contents] which will emit the 63 * [signal@GdkPaintable::invalidate-contents] signal. If a paintable is known 64 * to never change its contents, it will set the %GDK_PAINTABLE_STATIC_CONTENTS 65 * flag. If a consumer cannot deal with changing contents, it may call 66 * [method@Gdk.Paintable.get_current_image] which will return a static 67 * paintable and use that. 68 * 69 * A paintable can report an intrinsic (or preferred) size or aspect ratio it 70 * wishes to be rendered at, though it doesn't have to. Consumers of the interface 71 * can use this information to layout thepaintable appropriately. Just like the 72 * contents, the size of a paintable can change. A paintable will indicate this 73 * by calling [method@Gdk.Paintable.invalidate_size] which will emit the 74 * [signal@GdkPaintable::invalidate-size] signal. And just like for contents, 75 * if a paintable is known to never change its size, it will set the 76 * %GDK_PAINTABLE_STATIC_SIZE flag. 77 * 78 * Besides API for applications, there are some functions that are only 79 * useful for implementing subclasses and should not be used by applications: 80 * [method@Gdk.Paintable.invalidate_contents], 81 * [method@Gdk.Paintable.invalidate_size], 82 * [func@Gdk.Paintable.new_empty]. 83 */ 84 public template PaintableT(TStruct) 85 { 86 /** Get the main Gtk struct */ 87 public GdkPaintable* getPaintableStruct(bool transferOwnership = false) 88 { 89 if (transferOwnership) 90 ownedRef = false; 91 return cast(GdkPaintable*)getStruct(); 92 } 93 94 95 /** 96 * Compute a concrete size for the `GdkPaintable`. 97 * 98 * Applies the sizing algorithm outlined in the 99 * [CSS Image spec](https://drafts.csswg.org/css-images-3/#default-sizing) 100 * to the given @paintable. See that link for more details. 101 * 102 * It is not necessary to call this function when both @specified_width 103 * and @specified_height are known, but it is useful to call this 104 * function in GtkWidget:measure implementations to compute the 105 * other dimension when only one dimension is given. 106 * 107 * Params: 108 * specifiedWidth = the width @paintable could be drawn into or 109 * 0.0 if unknown 110 * specifiedHeight = the height @paintable could be drawn into or 111 * 0.0 if unknown 112 * defaultWidth = the width @paintable would be drawn into if 113 * no other constraints were given 114 * defaultHeight = the height @paintable would be drawn into if 115 * no other constraints were given 116 * concreteWidth = will be set to the concrete width computed 117 * concreteHeight = will be set to the concrete height computed 118 */ 119 public void computeConcreteSize(double specifiedWidth, double specifiedHeight, double defaultWidth, double defaultHeight, out double concreteWidth, out double concreteHeight) 120 { 121 gdk_paintable_compute_concrete_size(getPaintableStruct(), specifiedWidth, specifiedHeight, defaultWidth, defaultHeight, &concreteWidth, &concreteHeight); 122 } 123 124 /** 125 * Gets an immutable paintable for the current contents displayed by @paintable. 126 * 127 * This is useful when you want to retain the current state of an animation, 128 * for example to take a screenshot of a running animation. 129 * 130 * If the @paintable is already immutable, it will return itself. 131 * 132 * Returns: An immutable paintable for the current 133 * contents of @paintable 134 */ 135 public PaintableIF getCurrentImage() 136 { 137 auto __p = gdk_paintable_get_current_image(getPaintableStruct()); 138 139 if(__p is null) 140 { 141 return null; 142 } 143 144 return ObjectG.getDObject!(PaintableIF)(cast(GdkPaintable*) __p, true); 145 } 146 147 /** 148 * Get flags for the paintable. 149 * 150 * This is oftentimes useful for optimizations. 151 * 152 * See [flags@Gdk.PaintableFlags] for the flags and what they mean. 153 * 154 * Returns: The `GdkPaintableFlags` for this paintable 155 */ 156 public GdkPaintableFlags getFlags() 157 { 158 return gdk_paintable_get_flags(getPaintableStruct()); 159 } 160 161 /** 162 * Gets the preferred aspect ratio the @paintable would like to be displayed at. 163 * 164 * The aspect ratio is the width divided by the height, so a value of 0.5 165 * means that the @paintable prefers to be displayed twice as high as it 166 * is wide. Consumers of this interface can use this to preserve aspect 167 * ratio when displaying the paintable. 168 * 169 * This is a purely informational value and does not in any way limit the 170 * values that may be passed to [method@Gdk.Paintable.snapshot]. 171 * 172 * Usually when a @paintable returns nonzero values from 173 * [method@Gdk.Paintable.get_intrinsic_width] and 174 * [method@Gdk.Paintable.get_intrinsic_height] the aspect ratio 175 * should conform to those values, though that is not required. 176 * 177 * If the @paintable does not have a preferred aspect ratio, 178 * it returns 0. Negative values are never returned. 179 * 180 * Returns: the intrinsic aspect ratio of @paintable or 0 if none. 181 */ 182 public double getIntrinsicAspectRatio() 183 { 184 return gdk_paintable_get_intrinsic_aspect_ratio(getPaintableStruct()); 185 } 186 187 /** 188 * Gets the preferred height the @paintable would like to be displayed at. 189 * 190 * Consumers of this interface can use this to reserve enough space to draw 191 * the paintable. 192 * 193 * This is a purely informational value and does not in any way limit the 194 * values that may be passed to [method@Gdk.Paintable.snapshot]. 195 * 196 * If the @paintable does not have a preferred height, it returns 0. 197 * Negative values are never returned. 198 * 199 * Returns: the intrinsic height of @paintable or 0 if none. 200 */ 201 public int getIntrinsicHeight() 202 { 203 return gdk_paintable_get_intrinsic_height(getPaintableStruct()); 204 } 205 206 /** 207 * Gets the preferred width the @paintable would like to be displayed at. 208 * 209 * Consumers of this interface can use this to reserve enough space to draw 210 * the paintable. 211 * 212 * This is a purely informational value and does not in any way limit the 213 * values that may be passed to [method@Gdk.Paintable.snapshot]. 214 * 215 * If the @paintable does not have a preferred width, it returns 0. 216 * Negative values are never returned. 217 * 218 * Returns: the intrinsic width of @paintable or 0 if none. 219 */ 220 public int getIntrinsicWidth() 221 { 222 return gdk_paintable_get_intrinsic_width(getPaintableStruct()); 223 } 224 225 /** 226 * Called by implementations of `GdkPaintable` to invalidate their contents. 227 * 228 * Unless the contents are invalidated, implementations must guarantee that 229 * multiple calls of [method@Gdk.Paintable.snapshot] produce the same output. 230 * 231 * This function will emit the [signal@Gdk.Paintable::invalidate-contents] 232 * signal. 233 * 234 * If a @paintable reports the %GDK_PAINTABLE_STATIC_CONTENTS flag, 235 * it must not call this function. 236 */ 237 public void invalidateContents() 238 { 239 gdk_paintable_invalidate_contents(getPaintableStruct()); 240 } 241 242 /** 243 * Called by implementations of `GdkPaintable` to invalidate their size. 244 * 245 * As long as the size is not invalidated, @paintable must return the same 246 * values for its intrinsic width, height and aspect ratio. 247 * 248 * This function will emit the [signal@Gdk.Paintable::invalidate-size] 249 * signal. 250 * 251 * If a @paintable reports the %GDK_PAINTABLE_STATIC_SIZE flag, 252 * it must not call this function. 253 */ 254 public void invalidateSize() 255 { 256 gdk_paintable_invalidate_size(getPaintableStruct()); 257 } 258 259 /** 260 * Snapshots the given paintable with the given @width and @height. 261 * 262 * The paintable is drawn at the current (0,0) offset of the @snapshot. 263 * If @width and @height are not larger than zero, this function will 264 * do nothing. 265 * 266 * Params: 267 * snapshot = a `GdkSnapshot` to snapshot to 268 * width = width to snapshot in 269 * height = height to snapshot in 270 */ 271 public void snapshot(Snapshot snapshot, double width, double height) 272 { 273 gdk_paintable_snapshot(getPaintableStruct(), (snapshot is null) ? null : snapshot.getSnapshotStruct(), width, height); 274 } 275 276 /** 277 * Emitted when the contents of the @paintable change. 278 * 279 * Examples for such an event would be videos changing to the next frame or 280 * the icon theme for an icon changing. 281 */ 282 gulong addOnInvalidateContents(void delegate(PaintableIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 283 { 284 return Signals.connect(this, "invalidate-contents", dlg, connectFlags ^ ConnectFlags.SWAPPED); 285 } 286 287 /** 288 * Emitted when the intrinsic size of the @paintable changes. 289 * 290 * This means the values reported by at least one of 291 * [method@Gdk.Paintable.get_intrinsic_width], 292 * [method@Gdk.Paintable.get_intrinsic_height] or 293 * [method@Gdk.Paintable.get_intrinsic_aspect_ratio] 294 * has changed. 295 * 296 * Examples for such an event would be a paintable displaying 297 * the contents of a toplevel surface being resized. 298 */ 299 gulong addOnInvalidateSize(void delegate(PaintableIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 300 { 301 return Signals.connect(this, "invalidate-size", dlg, connectFlags ^ ConnectFlags.SWAPPED); 302 } 303 }